package com.first.springBoot.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.first.springBoot.domain.BusUser;
import com.first.springBoot.mapper.BusUserMapper;
import com.first.springBoot.service.BusUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * @描述: 用户服务接口实现类 .
 * @作者: Wnj .
 * @创建时间: 2017年6月20日 .
 * @版本: 1.0 .
 */
@Service
public class BusUserServiceImpl implements BusUserService {
    @Autowired
    private BusUserMapper busUserMapper;
    

	@Override
	public int insert(BusUser record) {
		return busUserMapper.insert(record);
	}

	@Override
	public int insertSelective(BusUser record) {
		return busUserMapper.insertSelective(record);
	}

	@Override
	@Cacheable(value="usermodom",keyGenerator="myKeyGenerator")
	public BusUser selectByPrimaryKey(Long id) {
		 return busUserMapper.selectByPrimaryKey(id);
	}

	@Override
	@Transactional
//	@CachEvict(value={”cache1”,”cache2”}
	@CacheEvict(value={"signonCache","usermodom"},allEntries=true)
	public int updateByPrimaryKeySelective(BusUser record) {
//		Map<String, Object>map = busUserMapper.update_Mysql_temp();
//		System.out.println(map);
		return busUserMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(BusUser record) {
		return busUserMapper.updateByPrimaryKey(record);
	}

	@Override
	@Cacheable(value="signonCache",keyGenerator="myKeyGenerator")
	@Transactional
	public List<BusUser> selectByCondition(Map<String, Object> map) {
//		BusUser record = new BusUser();
//		record.setUsername("dsadsadsadsad");
		
//		record.setId(2133L);
//		busUserMapper.updateByPrimaryKeySelective(record);
//		record.setUsername("dsad");
//		record.setOpenid("3:11.995 DEBUG 54068 --- [nio-8080-exec-8] org.mybatis.spring.SqlSessionUtils       : SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@47f8b430] was not registered for synch");
//		busUserMapper.updateByPrimaryKeySelective(record);
		int pageNum = map.get("pageNum")==null?0:(int)map.get("pageNum");
		int pageSize = map.get("pageSize")==null?1:(int)map.get("pageSize");
		PageHelper.startPage(pageNum, pageSize);  
		PageInfo<BusUser> a= new PageInfo<>( busUserMapper.selectByCondition(map));
		return a.getList();
	}
    
    
}
